package cn.school.common.utils;

import cn.school.student.entity.StudentInfo;
import cn.school.sys.enums.StatusEnums;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;

/**
 * @className: StudentInfoDetails
 * @author: fangjin.tao
 * @date: 2022/12/27
 **/
public class ParentUserInfoDetails implements UserDetails {
	private static final long serialVersionUID = 8605341996226864831L;
	private StudentInfo parentInfo;

	public ParentUserInfoDetails(StudentInfo parentInfo) {
		this.parentInfo = parentInfo;
	}

	public StudentInfo getParentInfo() {
		return parentInfo;
	}

	@Override
	public Collection<? extends GrantedAuthority> getAuthorities() {
		//返回当前用户的权限
		return null;
	}


	@Override
	public String getPassword() {
		return parentInfo.getGuardianPassword();
	}

	@Override
	public String getUsername() {
		return parentInfo.getGuardianPhoneNumber();
	}

	/**
	 * 账户是否未过期,过期无法验证
	 */
	@Override
	public boolean isAccountNonExpired() {
		return true;
	}

	/**
	 * 指定用户是否解锁,锁定的用户无法进行身份验证
	 *
	 * @return
	 */
	@Override
	public boolean isAccountNonLocked() {
		return true;
	}

	/**
	 * 指示是否已过期的用户的凭据(密码),过期的凭据防止认证
	 *
	 * @return
	 */
	@Override
	public boolean isCredentialsNonExpired() {
		return true;
	}

	/**
	 * 是否可用 ,禁用的用户不能身份验证
	 *
	 * @return
	 */
	@Override
	public boolean isEnabled() {
		return StatusEnums.ENABLE.getKey().equals(parentInfo.getStatus());
	}

	public StudentInfo getSysUser() {
		return this.parentInfo;
	}

	public void setSysUser(StudentInfo sysUser) {
		this.parentInfo = sysUser;
	}
}
